'use strict';

angular.module('inspinia')
  .controller('MainCtrl', function ($scope, $rootScope, $state) {


    // var mySlider = $("input.slider").slider();


    // // With JQuery
    // $("#ex13").slider({
    //   ticks: [0, 100, 200, 300, 400],
    //   ticks_labels: ['$0', '$100', '$200', '$300', '$400'],
    //   ticks_snap_bounds: 30
    // });




    $('body').addClass('mini-navbar');
    $rootScope.sideBarHidden = true;

    this.userName = 'Example user';
    this.helloText = 'Welcome in INSPINIA Gulp SeedProject';
    this.descriptionText = 'It is an application skeleton for a typical AngularJS web app. You can use it to quickly bootstrap your angular webapp projects.';
  })

  .controller('dirctorMainControl', function ($scope, users, $state,$rootScope,$log) {

    $('body').addClass('mini-navbar');
    // this.searchItem =function (index) {
    //   alert(index);
    // };
    init();
    function init() {
      IsPC();
      function IsPC() {
        var userAgentInfo = navigator.userAgent;
        // console.log(userAgentInfo);
        var Agents = ["Android", "iPhone",
          "SymbianOS", "Windows Phone",
          "iPad", "iPod"];
        $rootScope.PCview = true;
        for (var v = 0; v < Agents.length; v++) {
          if (userAgentInfo.indexOf(Agents[v]) > 0) {
            $rootScope.PCview = false;
            break;
          }
        }
        return $rootScope.PCview;
      }
      // console.log($rootScope.PCview);
      $scope.search = {};
      if (localStorage.getItem('regObj')) {
        $scope.patientList = JSON.parse(localStorage.getItem('regObj'));
        $.each(users, function (i, val) {
          $scope.patientList.push(val);
        })
        $scope.persons = $scope.patientList;
        setTimeout(function () {
          $('#mainTable').trigger('footable_redraw');
        }, 100)
      } else {
        $scope.patientList = [];
        $.each(users, function (i, val) {
          $scope.patientList.push(val);
        })

        $scope.persons = $scope.patientList;
        setTimeout(function () {
          $('#mainTable').trigger('footable_redraw');
        }, 100)
      }
    }

    $scope.searchItem = function (status) {
      $scope.persons = [];
      $.each($scope.patientList, function (i, val) {
        if (val.status == status) {
          $scope.persons.push(val);
        }
      })
      $log.debug($scope.persons)
      setTimeout(function () {
        $('#mainTable').trigger('footable_redraw');
      }, 100)
    }
    $scope.openModelForm = function (person) {
      localStorage.setItem('modelMessages', JSON.stringify(person));
      $state.go('index.modelForm');
    }
    $scope.goValidate = function () {
      window.location.href = "#/index/validate";
    };
  });


